﻿using StoneAge.Contract;
using StructureMap;

namespace StoneAge.Controller.Handlers
{
    class HandlerFactory : IHandlerFactory
    {
        public RequestHandler GetHandlers()
        {
            LoginHandler handlers = CreateLoginHandler();
            handlers.SetNextHandler(new CheckLoginHandler())
                .SetNextHandler(CreateCreateRoleHandler())
                .SetNextHandler(CreateGetMapHandler())
                .SetNextHandler(CraeteChooseRoleHandler())
                .SetNextHandler(new InvalidHandler());
            return handlers;
        }

        private LoginHandler CreateLoginHandler()
        {
            return new LoginHandler(ObjectFactory.GetInstance<IAccountService>());
        }

        private CreateRoleHandler CreateCreateRoleHandler()
        {
            return new CreateRoleHandler(ObjectFactory.GetInstance<IRoleService>());
        }

        private GetMapHandler CreateGetMapHandler()
        {
            return new GetMapHandler(ObjectFactory.GetInstance<IMapService>());
        }

        private ChooseRoleHandler CraeteChooseRoleHandler()
        {
            return new ChooseRoleHandler(ObjectFactory.GetInstance<IRoleService>());
        }
    }
}
